Home:ALL Converter>Why am I sometimes not getting a response with 2captcha API?

Why am I sometimes not getting a response with 2captcha API?

Ask Time:2018-11-09T06:23:50         Author:Ben Ammar Amine

Json Formatter

I am trying to solve recaptcha V2 with API 2captcha ,

I am using this code:

<?php
function token(){
    $apiKey = "MY_API_KEY";
    $googleKey = "6LfBixYUAAAAABhdHynFUIMA_sa4s-XsJvnjtgB0";
    $pageUrl = "https://example.com/";
    $time = time();
    while ( true ) {
       $retrieve= file_get_contents("http://2captcha.com/in.php?key=".$apiKey."&method=userrecaptcha&googlekey=".$googleKey."&pageurl=".$pageUrl, false, $ctx);
       $first = array($retrieve);
       $result = explode('OK|',$first[0]);
       $hello = $result[1];
       $con="http://2captcha.com/res.php?key=".$apiKey."&action=get&id=".$hello;

       sleep(23);
       $getting = file_get_contents($con);
       $second = array($getting);
       $secondresult = explode('OK|',$second[0]);
       $reponsetoken = $secondresult[1];
       echo'<br/>';
       echo'<br/>';
       echo'get new captcha token ...';
       echo'<br/>';
       echo'<br/>';
       if ((time() - $time) >= 99) {
          echo date("Y:m:d g:i:s"), PHP_EOL;
          $time = time();
       }
       sleep(2);
    }
}

if (!empty($reponsetoken)) {
    file_put_contents( 'token.txt', $reponsetoken );
}  else{token();}
?>

Why am I sometimes not getting a response?

I am trying to make condition with a timeout here.

$retrieve= file_get_contents("http://2captcha.com/in.php?key=".$apiKey."&method=userrecaptcha&googlekey=".$googleKey."&pageurl=".$pageUrl, false, $ctx);

Then I want to loop all the code every 2 min 30 secs.

How can I use condition with file_get_contents()?

How to do loop the code every 2 min 30 secs?

Author:Ben Ammar Amine,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53217067/why-am-i-sometimes-not-getting-a-response-with-2captcha-api
yy